<template>
    <el-dialog title="题目审核" :visible="showDialog" width="500px" @close="closeDialog">
    <!-- 表单 -->
    <el-form ref="addForm" :model="form">
    <el-form-item prop="usernam">
      <el-radio-group v-model="form.resource">
        <el-radio label="通过"></el-radio>
        <el-radio label="拒绝"></el-radio>
      </el-radio-group>
      <el-form-item prop="mobile">
        <el-input type="textarea" v-model="form.desc"></el-input>
      </el-form-item>
    </el-form-item>
    </el-form>
    <!-- footer插槽 -->
    <template v-slot:footer>
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="submitAdd">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
// 引入审核接口
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    shenHe: {
      type: Object
    }
  },
  data () {
    return {
      // 表单数据
      form: {
        resource: '',
        desc: ''
      },
      data: {
        chkRemarks: '', // 意见
        chkState: null, // 通过或拒绝
        id: null
      }
    }
  },
  methods: {
    // 自定义事件关闭弹框
    closeDialog () {
      this.$emit('clase-dialog', false)
      this.form = {
        resource: '',
        desc: ''
      }
    },
    // 点击确定按钮
    submitAdd () {
      console.log(this.form.resource)
      const state = this.form.resource
      if (state === '通过') {
        this.data.chkState = 2
      } else if (state === '拒绝') {
        this.data.chkRemarks = 3
      } else {
        this.data.chkState = 1
      }
      this.data.chkRemarks = this.form.desc
      this.data.id = this.shenHe.id

      this.$refs.addForm.validate(async flag => {
        if (!flag) return
        await choiceCheck(this.data) // 调用新增接口
        this.$message.success('添加成功')
        // 关闭弹框
        this.closeDialog()
        // 通知到父组件更新数据
        this.$parent.hChoice()
      })
    }
  }
}
</script>

<style>
</style>
